package ttk.muxiuesd.event;

import ttk.muxiuesd.entity.Entity;
import ttk.muxiuesd.entity.EntityGroup;
import ttk.muxiuesd.entity.Player;
import ttk.muxiuesd.entity.enemy.Slime;
import ttk.muxiuesd.util.Position;
import ttk.muxiuesd.util.Util;

/**
 * 史莱姆死亡事件
 * */
public class SlimeDeadEvent implements EntityDeadEvent{
    @Override
    public void execute(EntityGroup entityGroup, Entity entity) {
        if (entity instanceof Slime) {
            Slime slime = (Slime) entity;
            int generation = slime.generation;
            if (generation < 3) {
                Player player = entityGroup.player;
                for (int i = 0; i < 3; i++) {
                    //Position position = player.getPosition();
                    Position position = slime.getPosition();
                    float x = (float) (position.x + 1.5f * Util.randomCos());
                    float y = (float) (position.y + 1.5f * Util.randomSin());
                    new Slime(entityGroup, generation + 1)
                        .setBounds(x, y, slime.getWidth() * slime.factor, slime.getHeight() * slime.factor);
                }
            }
        }
    }
}
